﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MySecondWPFDemo
{
    class MyWindow : Window
    {
        private Button btn_submit;

        public MyWindow()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            //设置窗体
            this.Width = 285;
            this.Height = 250;
            this.Left = this.Top = 100;
            this.Title = "MyWindow";

            //创建停靠面板对象
            DockPanel panel = new DockPanel();

            //创建按钮对象
            btn_submit = new Button()
            {
                Content = "点我!",
                Margin = new Thickness(30),
            };

            btn_submit.Click += btn_submit_Click;

            IAddChild container = panel;    //当前容器为停靠面板panel
            container.AddChild(btn_submit); //将btn_submit按钮添加到panel中

            container = this;               //当前容器为窗体
            container.AddChild(panel);      //将停靠面板panel添加到窗体中
        }

        private void btn_submit_Click(object sender,RoutedEventArgs e)
        {
            btn_submit.Content = "傻逼!";
        }
    }
}
